package com.example.appstorenew.adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.DrawableImageViewTarget;
import com.bumptech.glide.request.target.ViewTarget;
import com.bumptech.glide.request.transition.Transition;
import com.example.appstorenew.R;
import com.example.appstorenew.pojo.appRecommend;
import com.example.appstorenew.utils.BaseUrl;


import java.util.List;

public class appRecommendAdapter extends BaseAdapter {

    private Context mContext;
    private List<appRecommend> appRecommendList;

    public appRecommendAdapter(Context mContext, List<appRecommend> appRecommendList) {
        this.mContext = mContext;
        this.appRecommendList = appRecommendList;
    }

    public Context getmContext() {
        return mContext;
    }

    public void setmContext(Context mContext) {
        this.mContext = mContext;
    }

    public List<appRecommend> getAppRecommendList() {
        return appRecommendList;
    }

    public void setAppRecommendList(List<appRecommend> appRecommendList) {
        this.appRecommendList = appRecommendList;
    }

    @Override
    public int getCount() {
        return appRecommendList.size();
    }

    @Override
    public Object getItem(int position) {
        return appRecommendList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        convertView = LayoutInflater.from(mContext).inflate(R.layout.item_apprecommend,null);

        LinearLayout lv_bg = convertView.findViewById(R.id.lv_bg);
        ImageView iv_img = convertView.findViewById(R.id.iv_logoPic);
        TextView tv_imgname = convertView.findViewById(R.id.tv_imgname);
        TextView tv_imgintroduce = convertView.findViewById(R.id.tv_imgintroduce);

        appRecommend appRecommend = appRecommendList.get(position);

        // 使用Glide加载图片并设置为背景，这里使用ViewTarget来指定目标为LinearLayout


        Glide.with(mContext).load(BaseUrl.baseUrl+"/dev-api"+appRecommend.getLogoPic()).into(iv_img);
        tv_imgname.setText(appRecommend.getApkName());
        tv_imgintroduce.setText(appRecommend.getIntroduce());

        return convertView;
    }
}
